package cn.jhc.servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;

import cn.jhc.bean.User;
import cn.jhc.db.UserDao;
import uuntil.*;
/**
 * Servlet implementation class ListUserServlet
 */
@WebServlet("/listuser.do")
public class ListUserServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
   
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		DataSource dataSource = (DataSource)request.getServletContext().getAttribute(Constants.H2_DATASOURCE);
		response.setContentType("appliction/json;charset=utf8");	
//		try {
//			UserDao.deleteAll(dataSource);
//		} catch (SQLException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
		List<User> users=UserDao.findAll(dataSource);
		request.setAttribute("users", users);
		request.getRequestDispatcher("listuser.jsp").forward(request, response);
		
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
		 
	}

	
}
